<template>
  <div class="coll">
    <div class="type">
      <span class="iconfont" @click="goto()">&#xe779;</span>
      我的收藏
    </div>
    <div class="isture" v-if="is">
      <p>还没有收藏商品哦~</p>
    </div>
    <div class="shangpin">
      <div class="box" v-for="item in sc" :key="item.id">
        <router-link :to="{ path: '/home/commodity', query: { id: item.id } }">
          <div class="img">
            <img :src="item.img" alt="" />
          </div>
          <p>{{ item.name }}</p>
          <div class="ys">
            <span>￥{{ item.jg }}</span
            ><span>已售{{ item.ys }}件</span>
          </div>
        </router-link>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.coll {
  .type {
    text-align: center;
    line-height: 50px;
    font-size: 16px;
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 9999;
    border-bottom: 1px solid #ccc;
    font-weight: bold;
    color: rgb(116, 116, 116);
    text-align: center;
    background-color: white;
    span {
      position: absolute;
      display: block;
      height: 50px;
      width: 40px;
    }
    a {
      display: block;
      span {
        position: absolute;
        display: block;
        height: 50px;
        color: rgb(116, 116, 116);
        font-size: 25px;
        width: 40px;
        right: 0;
        top: 0;
      }
    }
  }
  .shangpin {
    background-color: rgb(247, 247, 247);
    margin: 50px 0 60px;
    display: flex;
    flex-wrap: wrap;
    .box {
      width: 48%;
      margin: 1%;
      a {
        display: block;
        background-color: white;
        height: 270px;
        .img {
          width: 100%;
          height: 190px;
          overflow: hidden;
          img {
            width: 100%;
            min-width: 190px;
          }
        }
        p {
          font-size: 15px;
          height: 30px;
          padding: 10px;
          color: rgb(49, 49, 49);
        }
        .ys {
          position: relative;
          height: 25px;
          span:nth-child(1) {
            position: absolute;
            left: 10px;
            font-size: 15px;
            line-height: 25px;
            color: red;
          }
          span:nth-child(2) {
            position: absolute;
            right: 10px;
            font-size: 12px;
            line-height: 25px;
            color: rgb(143, 143, 143);
          }
        }
      }
    }
  }
  .isture {
    margin-top: 200px;
    text-align: center;
    p {
      color: red;
    }
  }
}
</style>
<script>
import { mapState } from "vuex";
export default {
  name: "coll",
  data() {
    return {
      is: true,
    };
  },
  methods: {
    goto() {
      this.$router.go(-1);
    },
  },
  computed: {
    ...mapState(["sc"]),
  },
  mounted() {
    if (this.sc.length > 0) {
      this.is = false;
    } else {
      this.is = true;
    }
  },
  beforeUpdate() {
    if (this.sc.length > 0) {
      this.is = false;
    } else {
      this.is = true;
    }
  },
};
</script>